package com.jyw.business.ast.domain.dto.web;

import com.jyw.business.ast.domain.AstConsumableClaim;
import com.jyw.business.ast.domain.AstConsumableRecord;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import com.jyw.common.utils.bean.BeanUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("耗材申领-请求实体")
public class AstConsumableClaimDto {

    /** 申请科室 */
    @ApiModelProperty("申请科室")
    private Long inDept;

    /** 备注 */
    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("申领耗材目录")
    private List<ReserveDto> reserveList;

    public AstConsumableClaim buildClaim() {
        AstConsumableClaim claim = new AstConsumableClaim();
        BeanUtils.copyProperties(this,claim);
        claim.setAuditState("0");
        claim.setCreateUser(SecurityUtils.getUserId());
        claim.setCreateTime(DateUtils.getNowDate());
        return claim;
    }

    public List<AstConsumableRecord> buildClaimRecord(AstConsumableClaim claim) {
        return getReserveList().stream().map(data -> {
            AstConsumableRecord record = new AstConsumableRecord();
            record.setType("1");
            record.setBusinessId(claim.getId());
            record.setConsumableId(data.getId());
            record.setQuantity(data.getQuantity());
            record.setRemark(getRemark());
            record.setCreateUser(SecurityUtils.getUserId());
            record.setCreateTime(DateUtils.getNowDate());
            return record;
        }).collect(Collectors.toList());
    }
}
